package com.cccyy.msgcode;

import java.security.SecureRandom;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class MsgCode {
    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(10);
        for (int i = 0; i < 9; i++) {
            executorService.submit(new Runnable() {
                @Override
                public void run() {
                    randomNum();
                    getRandomNum("123", 7);
                }
            });
        }
        executorService.shutdown();
    }

    private static void randomNum() {
        SecureRandom secureRandom = new SecureRandom();
        double v = secureRandom.nextDouble();
        int v1 = (int) ((v * 9 + 1) * 100000);
        System.out.println("生成的验证码为：" + v1);
    }

    private static void getRandomNum(String pre, int num) {
        String source = "0123456789";
        SecureRandom secureRandom = new SecureRandom();
        StringBuilder stringBuilder = new StringBuilder();
        int len = num - pre.length();
        for (int i = 0; i < len; i++) {
            stringBuilder.append(source.charAt(secureRandom.nextInt(source.length())));
        }
        String s = pre + stringBuilder;
        System.out.println("方法2生成的数据为：" + s);
    }

}
